﻿@{
    ViewBag.Title = "SerializeObject";
    Layout = "~/Views/Shared/_Page.cshtml";
}

<script type="text/javascript">

    window.onload = function () {
        /*
        JSON
        */

        var book = {
            "title": "Javascript Definitive Guide",
            "publish date": "2009-05-08",
            author: {
                firstname: "David",
                lastname: "Flanagan"
            }
        };

        var cloneBook = ObjUtil.deepCopy(book);
        cloneBook.title = "Thinking in Java";
        cloneBook["publish date"] = "2005-09-02";
        cloneBook.author.firstname = "Bruce";
        cloneBook.author.lastname = "Eckle";

        jsonCloneBook = JSON.stringify(cloneBook);
        jsonBook = JSON.stringify(book);

        ZEUS.DEBUG.log("1. ** JSON **");
        ZEUS.DEBUG.log("json book: " + jsonBook);
        ZEUS.DEBUG.log("cloned json book: " + jsonCloneBook);

        ZEUS.DEBUG.log("<br />");

        ZEUS.DEBUG.log("2. ** JSON Parse **");
        var cloneBook = JSON.parse(jsonCloneBook);
        ZEUS.DEBUG.log("Clone Book Info:");
        ObjUtil.printProperties(cloneBook);

        ZEUS.DEBUG.log("<br />");

        // parse array 
        ZEUS.DEBUG.log("3. ** JSON Parse String of Array **");
        ZEUS.DEBUG.log("Person List:");
        ZEUS.DEBUG.log("--------------------");
        var strArr = "[{ \"ID\": \"1\", \"Name\": \"David\", \"Age\": \"34\" }, { \"ID\": \"2\", \"Name\": \"Lynn\", \"Age\": \"32\"}]";
        var persons = JSON.parse(strArr);
        for (var i = 0; i < persons.length; i++) {
            var person = persons[i];
            for (var prop in person) {
                if (person.hasOwnProperty(prop)) { // filter
                    ZEUS.DEBUG.log(prop + ": " + person[prop]);
                }
            }
            ZEUS.DEBUG.log("--------------------");
        }
    }

</script>

<h2>Serialize Object</h2>
<br />
<h3>Path: @ViewBag.Path</h3>
<br />
<h3>Extended JS: /JsLib/G_Core.js</h3>
<br />
<h3>See the result on console</h3>
<br />
